layui.define(['jquery', 'layer','checkUtil'], function (exports) {
    var $ = layui.jquery,
        checkUtil = layui.checkUtil;
    var layer =layui.layer;
    var dialogUtil = {

        /***
         * 询问框方法
         * @param message 内容
         * @param successFn 点击‘确定’回调方法
         * @param cancelFn 点击‘取消’回调方法
         */
        alert: function (messag) {
            layer.alert(messag);
        },
        /***
         * 询问框方法
         * @param message 内容
         * @param successFn 点击‘确定’回调方法
         * @param cancelFn 点击‘取消’回调方法
         */
        confirm: function (message,successFn,cancelFn) {
            dialogUtil.confirmTitleMessage("信息",message,successFn,cancelFn);
        },
        /***
         * 询问框方法
         * @param title 标题
         * @param message 内容
         * @param successFn 点击‘确定’回调方法
         * @param cancelFn 点击‘取消’回调方法
         */
        confirmTitleMessage: function (title,message,successFn,cancelFn) {
            dialogUtil.confirmBase(title,message,['确定', '取消'],successFn,cancelFn);
        },
        /***
         * 询问框方法
         * @param message 内容
         * @param btn 按钮
         * @param successFn 点击‘确定’回调方法
         * @param cancelFn 点击‘取消’回调方法
         */
        confirmMessageBtn: function (message,btn,successFn,cancelFn) {
            dialogUtil.confirmBase("信息",message,btn,successFn,cancelFn);
        },
        /***
         * 询问框方法
         * @param title 标题
         * @param message 内容
         * @param btn 按钮
         * @param successFn 点击‘确定’回调方法
         * @param cancelFn 点击‘取消’回调方法
         */
        confirmBase: function (title,message,btn,successFn,cancelFn) {
            layer.confirm(message, {
                title:title,
                btn: btn,
                shade: [0.1, '#fff']
            }, function (index) {
                layer.close(index);
                if(typeof successFn=='function'){
                    successFn();
                }
            }, function (index) {
                layer.close(index);
                if(typeof cancelFn=='function'){
                    cancelFn();
                }
            });
        },
        /**
         * 提示框
         *
         * @param msg 提示内容
         * @author shengQiang yu
         * @date 2019-03-05 15:40
         */
        msg: function (msg) {
            layer.msg(msg, {time: 1 * 1000});
        },
        /**
         * 弹窗页面
         *
         * @param title 标题
         * @param url 连接
         * @param width 弹窗宽
         * @param height 弹窗高
         * @author shengQiang yu
         * @date 2019-03-11 9:44
         */
        popUp: function (title, url,successFn,width, height) {
            if (checkUtil.isEmpty(title)) {
                title = false;
            };
            var isFull=false;
            if (checkUtil.isEmpty(width)||checkUtil.isEmpty(height)) {
                isFull=true;
            };
            var index = layer.open({
                type: 2,
                title: title,
                area: [width, height],
                fixed: false, //不固定
                maxmin: true,
                content: url,
                success: function (layero, index) {
                    var body = layui.layer.getChildFrame('body', index);
                    body.find(".cancel").bind("click",function () {
                        layer.close(index);
                    })
                    if(isFull){
                        layer.full(index);
                    }
                    if(typeof successFn=='function'){
                        successFn(layero, index);
                    }
                }
            });
        },
        /**
         * 基础单选选择器弹窗页面
         *
         * @param title 标题
         * @param url 连接
         * @param successFn 成功回调
         * @param width 弹窗宽
         * @param height 弹窗高
         * @author shengQiang yu
         * @date 2019-03-11 9:44
         */
        popUpSingleSelect: function (title, url,successFn, width, height) {
            if (checkUtil.isEmpty(title)) {
                title = "选择器";
            }
            if (checkUtil.isEmpty(width)) {
                width = 380;
            }
            if (checkUtil.isEmpty(height)) {
                height = 560;
            }
            dialogUtil.popUp(title,"/base/selector/single?url=" + url, function (layer, index) {
                var body = layui.layer.getChildFrame('body', index);
                body.find("#save").bind("click", function () {
                    debugger
                    var id = body.find("#resultId").val();
                    var name = body.find("#resultName").val();
                    layui.layer.close(index);
                    if(typeof successFn=='function'){
                        successFn(id,name,layer,index);
                    }
                });
                body.find("#cancel").bind("click", function () {
                    layui.layer.close(index);
                });
            },width+'px',height+'px');
        },
        /**
         * 基础多选选择器弹窗页面
         *
         * @param title 标题
         * @param url 连接
         * @param successFn 成功回调
         * @param initIds 初始化选中对象id集合，多个用“,”隔开
         * @param width 弹窗宽
         * @param height 弹窗高
         * @author shengQiang yu
         * @date 2019-03-11 9:44
         */
        popUpMultSelect: function (title, url,successFn,initIds,width, height) {
            //初始化选中对象id集合
            var params = [];
            params.push(initIds);
            //初始化id值
            parent.cytSetSelectObjctParams(params);

            if (checkUtil.isEmpty(title)) {
                title = "选择器";
            }
            if (checkUtil.isEmpty(width)) {
                width = 380;
            }
            if (checkUtil.isEmpty(height)) {
                height = 560;
            }
            dialogUtil.popUpPage(title,"/base/selector/mult?url=" + url,width+'px',height+'px', function (layer, index) {
                var body = layer.getChildFrame('body', index);
                body.find("#save").bind("click", function () {
                    var id = body.find("#resultId").val();
                    var name = body.find("#resultName").val();
                    if(typeof successFn=='function'){
                        successFn(id,name,layer,index);
                    }
                    parent.layer.close(index);
                });
                body.find("#cancel").bind("click", function () {
                    parent.layer.close(index);
                });
            });
        },
        /**
         * 提示
         * @param title
         * @param obj
         */
        tips: function (title, obj) {
            layer.tips(title, obj, {
                tips: [1, '#444c63'], //还可配置颜色
                time: 1000
            });
        }
    };
    //输出dialogUtil接口
    exports('dialogUtil', dialogUtil);
});
